<?php
#------------------------------------------------------------------------
/**
 * 
 * This function will change directly the input string
 * @param string $string
 */
function stringEscapeString(&$string) {
	$string = mysql_escape_string($string);
}

#------------------------------------------------------------------------
/**
 * This function will add directly the apostrophe ' to input string
 * @param string $string
 */
function stringAddApostrophe(&$string) {
	$string = "'".$string."'";
}

#------------------------------------------------------------------------
/**
 * This function will remove directly the breakline character \r\n of input string
 * @param string $string
 */
function stringRemoveLineBreak(&$string) {
	$string = str_replace('\r\n', "", $string);
}

#-------------------------------------------------------------------------
/**
 * This function allow to transform all the date string Y-m-d in text format
 * @param string $date Format: Y-m-d
 */
function stringDateValueToText($date) {
  list($year, $month, $day) = explode('-', $date);
  
  if (("$year$month$day") == date('Ymd')) return 'Hôm nay';
  
  $month = 'tháng '.ltrim($month, '0');
  $day = ltrim($day, '0');
  
  return "$day $month";
}

#-------------------------------------------------------------------------
/**
 * This function allow to transform all the time string H:i:s in text format
 * @param string $date Format: H-i-s
 */
function stringTimeValueToText($time) {
  list($hour, $minute, $second) = explode(':', $time);
  
  return "${hour}h $minute";
}

#-------------------------------------------------------------------------
/**
 * Generate the random string
 * @param int $length Length of random string generated
 */
function stringGenRandomString($length) {
  $src = 'abcdefghijklmnopqrstuvxyzwABCDEFGHIJKLMNOPQRSTUVXYZW';
  return substr(str_shuffle($src), 0, $length);
}